package com.yaolong.api.modules.gen.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.yaolong.commons.response.ResponseResult;
import com.yaolong.commons.utils.ListPageUtil;
import com.yaolong.api.modules.gen.dao.TemplateFileDao;
import com.yaolong.api.modules.gen.model.entity.DataSource;
import com.yaolong.api.modules.gen.service.ITableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yaolong
 * @version V1.0.0
 * @program AgileFastFK3.0
 * @description
 * @create 2023-01-03 17:26
 **/
@RestController
@RequestMapping("/api/gen/table")
@Api(tags = "表信息管理")
public class TableServiceController {

    @Autowired
    ITableService tableService;

    @GetMapping("/page")
    @ApiOperation(value = "获取表信息列表", notes = "获取表信息列表")
    public ResponseResult list(@ModelAttribute DataSource dataSource,String removePrefixs, @RequestParam int current, @RequestParam int size) {
        List<TableInfo> list = tableService.list(dataSource, removePrefixs);
        ListPageUtil<TableInfo> listPageUtil = new ListPageUtil<>(list, current, size);
        IPage<TableInfo> pageInfo = new Page<>();
        pageInfo.setPages(listPageUtil.getPages());
        pageInfo.setTotal(listPageUtil.getTotal());
        pageInfo.setRecords(listPageUtil.getPagedList());
        return ResponseResult.success(pageInfo);
    }
}
